package cn.gmph.blog.admin.service.term.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gmph.blog.admin.service.term.dao.helper.TermmetaProvider;
import cn.gmph.blog.admin.service.term.entity.TermmetaDO;

import java.util.List;;

public interface TermmetaDAO {

    @Results({@Result( column = "meta_id",property = "metaId"),@Result( column = "term_id",property = "termId"),@Result( column = "meta_key",property = "metaKey"),@Result( column = "meta_value",property = "metaValue") })
    @Select("SELECT * FROM wp_termmeta WHERE id = #{id}")
    public TermmetaDO getById(@Param("id") int id);

    @Insert("INSERT into wp_termmeta(meta_id,term_id,meta_key,meta_value) VALUES (#{metaId},#{termId},#{metaKey},#{metaValue})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(TermmetaDO termmeta);

    @Delete("DELETE FROM wp_termmeta WHERE id = #{id}")
    public int deleteById(@Param("id") int id);

    @UpdateProvider(type = TermmetaProvider.class, method = "update")
    public int update(@Param("termmeta") TermmetaDO  termmeta);

    @Results({@Result( column = "meta_id",property = "metaId"),@Result( column = "term_id",property = "termId"),@Result( column = "meta_key",property = "metaKey"),@Result( column = "meta_value",property = "metaValue") })
    @SelectProvider(type = TermmetaProvider.class, method = "pageList")
    public List<TermmetaDO> pageList(@Param("termmeta") TermmetaDO termmeta, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = TermmetaProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("termmeta") TermmetaDO termmeta);

}